package czk.concrent.threadpool.timer.practice;

import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ThreadLocalRandom;
import java.util.concurrent.TimeUnit;

/**
 * 阿里巴巴规范用来代替timerTask
 * @Author:ChenZhangKun
 * @Date: 2021/6/9 11:51
 */
public class ScheduledExecutorServiceDemo {
    public static void main(String[] args) {
        ScheduledExecutorService scheduledExecutorService = Executors.newScheduledThreadPool(2);
        // 执行任务
        // 延时一秒
        // 没有delay
        // 单位s
        scheduledExecutorService.scheduleAtFixedRate(() -> {
            System.out.println(ThreadLocalRandom.current().nextInt(10));
        }, 0, 5, TimeUnit.SECONDS);
    }
}
